// 用同步异步分别生成1000个文件，分别同步的耗时异步的耗时 
'use strict';
let fs=require("fs");
let StartTime=new Date().getTime;
if (!fs.existsSync("whb"))fs.mkdirSync("whb");
for(let i=1;i<1001;i++){
     fs.writeFileSync("./whb/"+i+".txt","I miss to you");

}
let EndTime=new Date().getTime();
console.log("同步耗时为"+(EndTime-StartTime));
// 异步耗时
var StartTime1=new Date().getDate();
if(!fs.existsSync("whb2"))fs.mkdirSync("whb2");
var Maxnum=0;
for(var i=0;i<1001;i++){
    fs.writeFile("./whb2/"+i+".txt","hollow",(err,date)=>{
        var EndTime1=new Date().getTime();
        if (Maxnum<(EndTime1-StartTime1)) {
            Maxnum=(EndTime1-StartTime1);
        }
    });

}
setTimeout(function () {
    console.log("异步耗时为"+Maxnum);
},2000)
for(var a=1;a<1001;a++){
    fs.readFile("./whb1"+a+".txt",'utf-8',(err,date)=>{
        console.log(date.toString());
    })
    fs.readFile("./whb1"+a+".txt",'ascii',(err,date)=>{
        console.log(date.toString());
    })
    fs.readFile("./whb2"+a+".txt",'utf-8',(err,date)=>{
        console.log(date.toString());
    })
    fs.readFile("whb2"+a+".txt",'ascii',(err,date)=>{
        console.log(date.toString());
    })
}






